/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/


#include "StdAfx.h"
#include <pgl/core/PGLFont.h>
#include <pgl/core/PGLArchive.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNCREATE(CPGLFont,CObject);

//! Save settings
void CPGLFont::SerializeXML(CPGLArchive& ar)
{
	static TCHAR szTag[] = _T("CPGLFont");
	CString str;
		
	markup::CMarkupArchive& xml = *((markup::CMarkupArchive*)ar.GetMarkup());
	if(ar.IsStoring())
	{
		xml.AddChildElem(szTag);
		xml.IntoElem();
			xml.AddChildElem(_T("FaceName"),m_lf.lfFaceName);
			xml.AddChildElemEx(_T("Height"),m_lf.lfHeight);
			xml.AddChildElemEx(_T("Weight"),m_lf.lfWeight);
		xml.OutOfElem();
	}
	else
	{
		if  (!xml.FindChildElem(szTag))
				return;
	

		xml.IntoElem();
			if (xml.FindGetChildData(_T("FaceName"), str))
			{
				_tcscpy( m_lf.lfFaceName, str );
			}
			xml.FindGetChildData(_T("Height"),m_lf.lfHeight);
			xml.FindGetChildData(_T("Weight"),m_lf.lfWeight);
		xml.OutOfElem();
	}
}

#ifdef _DEBUG
void CPGLFont::Dump( CDumpContext& dc ) const
{
    // call base class function first
    CObject::Dump( dc );

	// now dumping..
	dc << _T("--- CPGLFont ---\n");
}

void CPGLFont::AssertValid() const
{
    // call inherited AssertValid first
    CObject::AssertValid();
} 
#endif


CPGLFont::CPGLFont()
{
	m_lf.lfHeight=8;
	m_lf.lfWidth=0;
	m_lf.lfEscapement=0;
	m_lf.lfOrientation=0;
	m_lf.lfWeight=FW_NORMAL;
	m_lf.lfItalic=FALSE;
	m_lf.lfUnderline=FALSE;
	m_lf.lfStrikeOut=FALSE;
	m_lf.lfCharSet=ANSI_CHARSET;
	m_lf.lfOutPrecision=OUT_TT_PRECIS;
	m_lf.lfClipPrecision=CLIP_DEFAULT_PRECIS;
	m_lf.lfQuality=ANTIALIASED_QUALITY;
	m_lf.lfPitchAndFamily=FF_DONTCARE|DEFAULT_PITCH;
	_tcscpy(m_lf.lfFaceName,_T("Verdana"));
}

CPGLFont::~CPGLFont()
{
}

void CPGLFont::SetFontGfx(gfxinterface::CGfxInterface& gfx)
{
	// getting information on font
	gfx.SetFont(m_lf);
}

POINTFLOAT CPGLFont::GetTextExtent(const CString &string)
{
	POINTFLOAT pf;

	pf.x=0;
	pf.y=0;
	return pf;
}
